<div class="left-sidebar">
    <h2>Categories</h2>
    <?php
    //Get Active Categories
    $result = mysql_query("SELECT * FROM `categories` WHERE active = 1");

    $category_side_menu = '';

    while ($row = mysql_fetch_array($result)) {

        $product_side_menu = '';

        $result2 = mysql_query("SELECT * FROM `products` WHERE active = 1 AND category_id = '" . $row['category_id'] . "'");
        
        $product_side_menu_items = '';
        
        while ($row2 = mysql_fetch_array($result2)) {
            $product_side_menu_items .= '<li><a href="product_details.php?pid=' . $row2['product_id'] . '">' . $row2['product'] . '</a></li>';
        }
        $product_count = mysql_num_rows($result2);
        if(!empty($product_count)){

        $product_side_menu = '<div id="' . $row['category_id'] . '" class="panel-collapse collapse">
                                <div class="panel-body">
                                    <ul>
                                        ' . $product_side_menu_items . '
                                    </ul>
                                </div>
                            </div>';
        $product_attributes = '<span class="badge pull-right"><i class="fa fa-plus"></i></span>';
        } else {
            $product_side_menu = "";
            $product_attributes = "";
        }

        $category_side_menu .= '
              
          <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordian" href="#' . $row['category_id'] . '">
                        '. $product_attributes .'                  
                            ' . $row['category'] . '
                        </a>
                </h4>
            </div>
                        ' . $product_side_menu . '
        </div>';
    }

    print '<div class="panel-group category-products" id="accordian">' . $category_side_menu . '</div>';
    ?>

    <div class="shipping text-center"><!--shipping-->
        <img src="images/home/shipping.jpg" alt="" />
    </div><!--/shipping-->

</div>